Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
How do I define discord. "error discord is not defined"
const { Client, Intents, DiscordAPIError } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

const ytdl = require("ytdl-core")

const fs = require('fs');

client.commands = new Discord.Collection(); //error here

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`)
    
    client.commands.set(command.name, command);
}

const PREFIX = '$';

var version = '1.0.1'

var servers = {};


client.once('ready', () => {
    console.log ('Smegma Music is online!');
});

client.on('message', message=>{
    if(!message.content.startsWith(PREFIX) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args. shift().toLowerCase();

    if(command === 'ping'){
        message.channel.send('Shutup Bitch!');{

        }


            function play(connection, message){
                var server = servers [message.guild.id];

                server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: "audioonly"}));

                server.queue.shift();

                server.dispatcher.on("end", function(){
                    if(server.queue[0]){
                        play(connection, message);
                    }else {
                        connection.disconnect();
                    }

                });
                client.login('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); //at end
            }
}});

Line 9 is where the problem is. "client.commands = new Discord.Collection();" I get an error when I try to run 'node .' saying

ReferenceError: Discord is not defined at Object. (C:\MusicBot\main.js:9:23)

It was working yesterday, however this was with a different approach to commands. I am trying to create a basic command handler here.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Above trying to make a new collection, you can define discord like this:

const Discord = require("discord.js")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!